{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## 配列の使い方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Name:Taro Age:21 Address:Tokyo\n",
      "Name:Hanako Age:18 Address:Hokkaido\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "### 変数の設定\n",
    "name=PersonTest\n",
    "\n",
    "### ソースの編集\n",
    "cat <<- EOS > ${name}.java\n",
    "\n",
    "class Person {\n",
    "  String name;\n",
    "  int age;\n",
    "  String address;\n",
    "  \n",
    "  Person(String _name, int _age, String _address){\n",
    "    name = _name;\n",
    "    age = _age;\n",
    "    address = _address;\n",
    "  }\n",
    "  \n",
    "  //# メソッドを定義\n",
    "  void say(){\n",
    "    System.out.println(\"Name:\" + name + \" Age:\" + age + \" Address:\" + address);\n",
    "  }\n",
    "}\n",
    "\n",
    "public class ${name} {\n",
    "  public static void main (String[] args) {\n",
    "\n",
    "    //# 配列の定義。このnewは配列名の宣言\n",
    "    //# 配列のデータ型[] 配列名 = 配列の要素の型[要素数];\n",
    "    Person[] people = new Person[2];\n",
    "    //# このnewはインスタンスの生成\n",
    "    people[0] = new Person(\"Taro\", 21, \"Tokyo\");\n",
    "    people[1] = new Person(\"Hanako\", 18, \"Hokkaido\");\n",
    "    people[0].say();\n",
    "    people[1].say();\n",
    "  }\n",
    "}\n",
    "EOS\n",
    "\n",
    "### コンパイル\n",
    "#javac ${name}.java\n",
    "javac -encoding UTF-8 ${name}.java\n",
    "\n",
    "### 実行\n",
    "java ${name}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## for文の使い方"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Name:Taro Age:21 Address:Tokyo\n",
      "Name:Hanako Age:18 Address:Hokkaido\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "### 変数の設定\n",
    "name=PersonTest\n",
    "\n",
    "### ソースの編集\n",
    "cat <<- EOS > ${name}.java\n",
    "\n",
    "class Person {\n",
    "  String name;\n",
    "  int age;\n",
    "  String address;\n",
    "  \n",
    "  Person(String _name, int _age, String _address){\n",
    "    name = _name;\n",
    "    age = _age;\n",
    "    address = _address;\n",
    "  }\n",
    "  \n",
    "  //# メソッドを定義\n",
    "  void say(){\n",
    "    System.out.println(\"Name:\" + name + \" Age:\" + age + \" Address:\" + address);\n",
    "  }\n",
    "}\n",
    "\n",
    "public class ${name} {\n",
    "  public static void main (String[] args) {\n",
    "\n",
    "    //# 配列の定義。このnewは配列名の宣言\n",
    "    //# 配列のデータ型[] 配列名 = 配列の要素の型[要素数];\n",
    "    Person[] people = new Person[2];\n",
    "    //# このnewはインスタンスの生成\n",
    "    people[0] = new Person(\"Taro\", 21, \"Tokyo\");\n",
    "    people[1] = new Person(\"Hanako\", 18, \"Hokkaido\");\n",
    "    \n",
    "    //# for文\n",
    "    for(int i = 0; i < people.length; i++){\n",
    "      people[i].say();\n",
    "    }\n",
    "  }\n",
    "}\n",
    "EOS\n",
    "\n",
    "### コンパイル\n",
    "#javac ${name}.java\n",
    "javac -encoding UTF-8 ${name}.java\n",
    "\n",
    "### 実行\n",
    "java ${name}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## フィールド変数の値を変える\n",
    "\n",
    "* `インスタンス名.フィールド名 = 値`\n",
    "    * ただし、この例のようにフィールドに直接アクセスできる状態はよくない\n",
    "        * 外部からのフィールドのアクセス制限が必要\n",
    "        * メソッドを経由してフィールドを操作するようにするべき (カプセル化によるクラスの保護)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Name:Jiro Age:19 Address:Tokyo\n",
      "Name:Hanako Age:18 Address:Hokkaido\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "### 変数の設定\n",
    "name=PersonTest\n",
    "\n",
    "### ソースの編集\n",
    "cat <<- EOS > ${name}.java\n",
    "\n",
    "class Person {\n",
    "  String name;\n",
    "  int age;\n",
    "  String address;\n",
    "  \n",
    "  Person(String _name, int _age, String _address){\n",
    "    name = _name;\n",
    "    age = _age;\n",
    "    address = _address;\n",
    "  }\n",
    "  \n",
    "  //# メソッドを定義\n",
    "  void say(){\n",
    "    System.out.println(\"Name:\" + name + \" Age:\" + age + \" Address:\" + address);\n",
    "  }\n",
    "}\n",
    "\n",
    "public class ${name} {\n",
    "  public static void main (String[] args) {\n",
    "\n",
    "    Person[] people = new Person[2];\n",
    "    people[0] = new Person(\"Taro\", 21, \"Tokyo\");\n",
    "    people[1] = new Person(\"Hanako\", 18, \"Hokkaido\");\n",
    "    \n",
    "    //# データを変更\n",
    "    //# フィールドに直接アクセスできる状態は良くない。。\n",
    "    people[0].name = \"Jiro\";\n",
    "    people[0].age = 19;\n",
    "    \n",
    "    for(int i = 0; i < people.length; i++){\n",
    "      people[i].say();\n",
    "    }\n",
    "  }\n",
    "}\n",
    "EOS\n",
    "\n",
    "### コンパイル\n",
    "#javac ${name}.java\n",
    "javac -encoding UTF-8 ${name}.java\n",
    "\n",
    "### 実行\n",
    "java ${name}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## カプセル化する\n",
    "\n",
    "* カプセル化\n",
    "    * クラスの外部からはフィールドを直接操作できないようにして、必ずメソッドを経由してフィールドを間接的に操作するようにすること\n",
    "        * <font color=\"red\">メソッドを経由することでデータをチェックしてからフィールドに設定できる</font>\n",
    "    * なぜカプセル化をするのか\n",
    "        * クラスを部品として再利用するため\n",
    "            * クラスのフィールドに不正な値が設定されるのはまずい\n",
    "                * 本来ありえない値を設定されてしまう恐れがある\n",
    "    * 実現方法\n",
    "        * 適切なアクセス修飾子をつける\n",
    "            * アクセス修飾子\n",
    "                * public : 全てのクラスからアクセス可能\n",
    "                    * クラス、インタフェース、フィールド、メソッドで利用可能\n",
    "                * protected : 同一クラス内、同一パッケージ、サブクラスからアクセス可能\n",
    "                    * 同一パッケージとは同じディレクトリ内にあるクラスファイル\n",
    "                       * クラスは使えない\n",
    "                    * フィールド、メソッドで利用可能\n",
    "                * 指定なし : 同一クラス内、同一パッケージからアクセス可能\n",
    "                    * クラス、インタフェース、フィールド、メソッドで利用可能                    \n",
    "                * private : 同一クラス内のみアクセス可能\n",
    "                    * フィールド、メソッドで利用可能\n",
    "                        * クラスは使えない\n",
    "        * セッター、ゲッターを定義する\n",
    "    * 参考\n",
    "        * static修飾子\n",
    "            * .<font color=\"red\">メソッドにstatic修飾子をつけるとクラスメソッドになる</font>\n",
    "                * クラス名.クラスメソッド の形でメソッドを実行できる\n",
    "                    * <font color=\"red\">new演算子でインスタンスを生成しなくても使える</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "PersonTest.java:2: error: class Person is public, should be declared in a file named Person.java\n",
      "public class Person {\n",
      "       ^\n",
      "PersonTest.java:29: error: name has private access in Person\n",
      "    people[0].name = \"Jiro\";\n",
      "             ^\n",
      "PersonTest.java:30: error: age has private access in Person\n",
      "    people[0].age = 19;\n",
      "             ^\n",
      "3 errors\n",
      "Exception in thread \"main\" java.lang.IllegalAccessError: tried to access field Person.name from class PersonTest\n",
      "\tat PersonTest.main(PersonTest.java:28)\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "### 変数の設定\n",
    "name=PersonTest\n",
    "\n",
    "### ソースの編集\n",
    "cat <<- EOS > ${name}.java\n",
    "\n",
    "//# publicクラスは1つのファイルに1つだけなので別のファイルにしなければならない\n",
    "public class Person {\n",
    "  //# フィールドにprivate修飾子を付与\n",
    "  private String name;\n",
    "  private int age;\n",
    "  private String address;\n",
    "  \n",
    "  //# コンストラクタにpublic修飾子を付与\n",
    "  public Person(String _name, int _age, String _address){\n",
    "    name = _name;\n",
    "    age = _age;\n",
    "    address = _address;\n",
    "  }\n",
    "  \n",
    "  //# say()メソッドにpublicメソッドを付与\n",
    "  public void say(){\n",
    "    System.out.println(\"Name:\" + name + \" Age:\" + age + \" Address:\" + address);\n",
    "  }\n",
    "}\n",
    "\n",
    "public class ${name} {\n",
    "  public static void main (String[] args) {\n",
    "\n",
    "    Person[] people = new Person[2];\n",
    "    people[0] = new Person(\"Taro\", 21, \"Tokyo\");\n",
    "    people[1] = new Person(\"Hanako\", 18, \"Hokkaido\");\n",
    "    \n",
    "    //# privateのフィールドに直接アクセスしようとしているのでコンパイルエラーになる\n",
    "    people[0].name = \"Jiro\";\n",
    "    people[0].age = 19;\n",
    "    \n",
    "    for(int i = 0; i < people.length; i++){\n",
    "      people[i].say();\n",
    "    }\n",
    "  }\n",
    "}\n",
    "EOS\n",
    "\n",
    "### コンパイル\n",
    "#javac ${name}.java\n",
    "javac -encoding UTF-8 ${name}.java\n",
    "\n",
    "### 実行\n",
    "java ${name}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## 書式まとめ\n",
    "\n",
    "### クラス\n",
    "\n",
    "```\n",
    "### 簡略系\n",
    "class クラス名 {\n",
    "  内容\n",
    "}\n",
    "\n",
    "### 正式形\n",
    "[修飾子] class クラス名[extends節][implement節]{\n",
    "  内容\n",
    "}\n",
    "```\n",
    "\n",
    "### フィールド\n",
    "\n",
    "```\n",
    "### 簡略系\n",
    "変数の型 フィールド名;\n",
    "\n",
    "### 正式系\n",
    "[修飾子] 変数の型　フィールド名;\n",
    "```\n",
    "\n",
    "### メソッドの書式\n",
    "```\n",
    "### 簡略系\n",
    "戻り値の型 メソッド名(仮引数のリスト){\n",
    "  内容\n",
    "  return 戻り値;\n",
    "}\n",
    "\n",
    "### 正式系\n",
    "[修飾子] 戻り値の型 メソッド名(仮引数のリスト){\n",
    "  内容\n",
    "  return 戻り値;\n",
    "}\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## セッターを使ってフィールドを間接的に操作する\n",
    "\n",
    "* セッター(setter)\n",
    "    * フィールドを間接的に操作するためのメソッド\n",
    "    * セッターのアクセス修飾子をpublicにすることでこれらのメソッドは他のクラスからアクセスできるようになる\n",
    "    * セッターのメソッドは<font color=\"red\">set + フィールド名(頭文字を大文字)</font>という特別な命名方法が推奨されている\n",
    "        * setName"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "%%bash\n",
    "### 変数の設定\n",
    "name=Person\n",
    "\n",
    "### ソースの編集\n",
    "cat <<- EOS > ${name}.java\n",
    "public class ${name} {\n",
    "  //# フィールドはprivateで隠蔽\n",
    "  private String name;\n",
    "  private int age;\n",
    "  private String address;\n",
    "  \n",
    "  public Person(String _name, int _age, String _address){\n",
    "    name = _name;\n",
    "    age = _age;\n",
    "    address = _address;\n",
    "  }\n",
    "  \n",
    "  public void say(){\n",
    "    System.out.println(\"Name:\" + name + \" Age:\" + age + \" Address:\" + address);\n",
    "  }\n",
    "  \n",
    "  //# セッターの設定。これを使ってフィールドにアクセスする\n",
    "  public void setName(String _name){\n",
    "    name = _name;\n",
    "  }\n",
    "  \n",
    "  public void setAge(int _age){\n",
    "    age = _age;\n",
    "  }\n",
    "  \n",
    "  public void setAddress(String _address){\n",
    "    address = _address;\n",
    "  }\n",
    "}\n",
    "EOS\n",
    "\n",
    "### コンパイル\n",
    "### mainメソッドの方をコンパイルするとこちらも自動的にコンパイルされる\n",
    "#javac ${name}.java\n",
    "#javac -encoding UTF-8 ${name}.java\n",
    "\n",
    "### 実行\n",
    "### mainメソッドは無くそもそも実行できない\n",
    "#java ${name}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Name:Taro Age:21 Address:Tokyo\n",
      "Name:Hanako Age:18 Address:Hokkaido\n",
      "Name:Jiro Age:19 Address:Osaka\n",
      "Name:Hanako Age:18 Address:Hokkaido\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "### 変数の設定\n",
    "name=PersonTest\n",
    "\n",
    "### ソースの編集\n",
    "cat <<- EOS > ${name}.java\n",
    "public class ${name} {\n",
    "  public static void main (String[] args) {\n",
    "\n",
    "    Person[] people = new Person[2];\n",
    "    people[0] = new Person(\"Taro\", 21, \"Tokyo\");\n",
    "    people[1] = new Person(\"Hanako\", 18, \"Hokkaido\");\n",
    "\n",
    "    for(int i = 0; i < people.length; i++){\n",
    "      people[i].say();\n",
    "    }\n",
    "\n",
    "    //# 代入では無くメソッドの引数の形式になっていることに注意\n",
    "    people[0].setName(\"Jiro\");\n",
    "    people[0].setAge(19);\n",
    "    people[0].setAddress(\"Osaka\");\n",
    "\n",
    "    for(int i = 0; i < people.length; i++){\n",
    "      people[i].say();\n",
    "    }\n",
    "\n",
    "  }\n",
    "}\n",
    "EOS\n",
    "\n",
    "### コンパイル\n",
    "#javac ${name}.java\n",
    "javac -encoding UTF-8 ${name}.java\n",
    "\n",
    "### 実行\n",
    "java ${name}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## セッターでデータをチェックする\n",
    "\n",
    "* クラスの安定化の流れまとめ\n",
    "    * アクセス修飾子とセッターを使ってフィールドを間接的に操作することでカプセル化\n",
    "    * データのチェックをしてからフィールドに設定することで不自然な値を設定できないようにしてクラスの動きを安定化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "%%bash\n",
    "### 変数の設定\n",
    "name=Person\n",
    "\n",
    "### ソースの編集\n",
    "cat <<- EOS > ${name}.java\n",
    "public class ${name} {\n",
    "  private String name;\n",
    "  private int age;\n",
    "  private String address;\n",
    "  \n",
    "  public Person(String _name, int _age, String _address){\n",
    "    name = _name;\n",
    "    age = _age;\n",
    "    address = _address;\n",
    "  }\n",
    "  \n",
    "  public void say(){\n",
    "    System.out.println(\"Name:\" + name + \" Age:\" + age + \" Address:\" + address);\n",
    "  }\n",
    "  \n",
    "  public void setName(String _name){\n",
    "    name = _name;\n",
    "  }\n",
    "  \n",
    "  //# データをチェックする。ありえない年齢が入ると0になる\n",
    "  public void setAge(int _age){\n",
    "    if (_age > 0) {\n",
    "      age = _age;\n",
    "    }else{\n",
    "      age = 0;\n",
    "    }\n",
    "  }\n",
    "  \n",
    "  public void setAddress(String _address){\n",
    "    address = _address;\n",
    "  }\n",
    "}\n",
    "EOS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Name:Taro Age:21 Address:Tokyo\n",
      "Name:Hanako Age:18 Address:Hokkaido\n",
      "Name:Jiro Age:19 Address:Osaka\n",
      "Name:Hanako Age:18 Address:Hokkaido\n",
      "Name:Saburo Age:0 Address:Nagoya\n",
      "Name:Hanako Age:18 Address:Hokkaido\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "### 変数の設定\n",
    "name=PersonTest\n",
    "\n",
    "### ソースの編集\n",
    "cat <<- EOS > ${name}.java\n",
    "public class ${name} {\n",
    "  public static void main (String[] args) {\n",
    "\n",
    "    Person[] people = new Person[2];\n",
    "    people[0] = new Person(\"Taro\", 21, \"Tokyo\");\n",
    "    people[1] = new Person(\"Hanako\", 18, \"Hokkaido\");\n",
    "\n",
    "    for(int i = 0; i < people.length; i++){\n",
    "      people[i].say();\n",
    "    }\n",
    "\n",
    "    people[0].setName(\"Jiro\");\n",
    "    people[0].setAge(19);\n",
    "    people[0].setAddress(\"Osaka\");\n",
    "\n",
    "    for(int i = 0; i < people.length; i++){\n",
    "      people[i].say();\n",
    "    }\n",
    "\n",
    "    //# ありえない年齢を設定\n",
    "    people[0].setName(\"Saburo\");\n",
    "    people[0].setAge(-5);\n",
    "    people[0].setAddress(\"Nagoya\");\n",
    "\n",
    "    for(int i = 0; i < people.length; i++){\n",
    "      people[i].say();\n",
    "    }\n",
    "\n",
    "  }\n",
    "}\n",
    "EOS\n",
    "\n",
    "### コンパイル\n",
    "#javac ${name}.java\n",
    "javac -encoding UTF-8 ${name}.java\n",
    "\n",
    "### 実行\n",
    "java ${name}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## ゲッターでデータを取得する\n",
    "\n",
    "* ゲッター\n",
    "    * ゲッターとよばれるメソッドでフィールドに設定された値を間接的に取得する\n",
    "    * 戻り値としてフィールドの値を呼び出して元に返す\n",
    "    * メソッド名は<font color=\"red\">get + フィールド名(頭文字大文字)</font>という特別な命名方法が推奨されている\n",
    "    * 戻り値を呼び出し元で出力できる\n",
    "        * <font color=\"red\">表示の仕方を手軽に変えることができる</font>\n",
    "        * say()メソッドは呼び出し先で出力している"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "%%bash\n",
    "### 変数の設定\n",
    "name=Person\n",
    "\n",
    "### ソースの編集\n",
    "cat <<- EOS > ${name}.java\n",
    "public class ${name} {\n",
    "  private String name;\n",
    "  private int age;\n",
    "  private String address;\n",
    "  \n",
    "  public Person(String _name, int _age, String _address){\n",
    "    name = _name;\n",
    "    age = _age;\n",
    "    address = _address;\n",
    "  }\n",
    "  \n",
    "  //# こっちのクラス(Person)で出力している\n",
    "  public void say(){\n",
    "    System.out.println(\"Name:\" + name + \" Age:\" + age + \" Address:\" + address);\n",
    "  }\n",
    "  \n",
    "  public void setName(String _name){\n",
    "    name = _name;\n",
    "  }\n",
    "  \n",
    "  public void setAge(int _age){\n",
    "    if (_age > 0) {\n",
    "      age = _age;\n",
    "    }else{\n",
    "      age = 0;\n",
    "    }\n",
    "  }\n",
    "  \n",
    "  public void setAddress(String _address){\n",
    "    address = _address;\n",
    "  }\n",
    "  \n",
    "  //# ゲッターの設定。フィールドの値を戻り値としてreturnで呼び出して返しているだけ。\n",
    "  public String getName(){\n",
    "    return name;\n",
    "  }\n",
    "  \n",
    "  public int getAge(){\n",
    "    return age;\n",
    "  }\n",
    "  \n",
    "  public String getAddress(){\n",
    "    return address;\n",
    "  }\n",
    "}\n",
    "EOS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Name:Taro Age:21 Address:Tokyo\n",
      "Name:Hanako Age:18 Address:Hokkaido\n",
      "Jiro 19 Osaka\n",
      "Hanako 18 Hokkaido\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "### 変数の設定\n",
    "name=PersonTest\n",
    "\n",
    "### ソースの編集\n",
    "cat <<- EOS > ${name}.java\n",
    "public class ${name} {\n",
    "  public static void main (String[] args) {\n",
    "\n",
    "    Person[] people = new Person[2];\n",
    "    people[0] = new Person(\"Taro\", 21, \"Tokyo\");\n",
    "    people[1] = new Person(\"Hanako\", 18, \"Hokkaido\");\n",
    "\n",
    "    for(int i = 0; i < people.length; i++){\n",
    "      //# say()メソッドはPersonクラス側で画面に出力している\n",
    "      people[i].say();\n",
    "    }\n",
    "\n",
    "    people[0].setName(\"Jiro\");\n",
    "    people[0].setAge(19);\n",
    "    people[0].setAddress(\"Osaka\");\n",
    "\n",
    "    //# ゲッターでデータを取得して表示。戻り値を呼び出し元で出力している\n",
    "    for(int i = 0; i < people.length; i++){\n",
    "      System.out.println(people[i].getName() + \" \" + people[i].getAge() + \" \" + people[i].getAddress());\n",
    "    }\n",
    "\n",
    "  }\n",
    "}\n",
    "EOS\n",
    "\n",
    "### コンパイル\n",
    "#javac ${name}.java\n",
    "javac -encoding UTF-8 ${name}.java\n",
    "\n",
    "### 実行\n",
    "java ${name}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
